local hx__zuyin = fk.CreateSkill {
  name = "hx__zuyin",
  tags = { Skill.Compulsory },
}

hx__zuyin:addEffect(fk.TargetConfirmed, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(hx__zuyin.name) and data.from ~= player and
      (data.card.trueName == "slash" or data.card:isCommonTrick())
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = table.filter(player:getPile("hx__yanzuo"), function(id)
      return Fk:getCardById(id).trueName == data.card.trueName
    end)
    if #cards > 0 then
      data.use.nullifiedTargets = table.simpleClone(room.alive_players)
      room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, hx__zuyin.name, nil, true, player)
    else
      if player:hasSkill("hx__yanzuo", true) and player:getMark("@hx__zuyin") < 6 then
        room:addPlayerMark(player, "@hx__zuyin", 1)
      end
      cards = room:getCardsFromPileByRule(data.card.trueName, 1, "allPiles")
      if #cards > 0 then
        player:addToPile("hx__yanzuo", cards, true, hx__zuyin.name, player)
      end
    end
  end,
})

return hx__zuyin
